package com.web.dao;

import com.web.entity.Platform;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.math.BigDecimal;

public interface PlatformMapper {
    @Delete({
        "delete from t_platform",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into t_platform (company_profit_pool, company_fund_pool, ",
        " market_fund_pool, bonus_pool,poundage_pool, ",
        " market_msk, company_msk, ",
        " create_time, modify_time)",
        " values (#{companyProfitPool,jdbcType=DECIMAL}, #{companyFundPool,jdbcType=DECIMAL}, ",
        " #{marketFundPool,jdbcType=DECIMAL}, #{bonusPool,jdbcType=DECIMAL},#{poundagePool,jdbcType=DECIMAL}, ",
        " #{marketMsk,jdbcType=DECIMAL}, #{companyMsk,jdbcType=DECIMAL}, ",
        " #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(Platform record);

    @InsertProvider(type=PlatformSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(Platform record);

    @Select({
        "select",
        " id, company_profit_pool, company_fund_pool, market_fund_pool, bonus_pool,poundage_pool, market_msk, ",
        " company_msk, create_time, modify_time",
        " from t_platform",
        " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="company_profit_pool", property="companyProfitPool", jdbcType=JdbcType.DECIMAL),
        @Result(column="company_fund_pool", property="companyFundPool", jdbcType=JdbcType.DECIMAL),
        @Result(column="market_fund_pool", property="marketFundPool", jdbcType=JdbcType.DECIMAL),
        @Result(column="bonus_pool", property="bonusPool", jdbcType=JdbcType.DECIMAL),
        @Result(column="poundage_pool", property="poundagePool", jdbcType=JdbcType.DECIMAL),
        @Result(column="market_msk", property="marketMsk", jdbcType=JdbcType.DECIMAL),
        @Result(column="company_msk", property="companyMsk", jdbcType=JdbcType.DECIMAL),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Platform selectByPrimaryKey(Long id);

    @UpdateProvider(type=PlatformSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Platform record);

    @Update({
        "update t_platform",
        " set company_profit_pool = #{companyProfitPool,jdbcType=DECIMAL},",
          " company_fund_pool = #{companyFundPool,jdbcType=DECIMAL},",
          " market_fund_pool = #{marketFundPool,jdbcType=DECIMAL},",
          " bonus_pool = #{bonusPool,jdbcType=DECIMAL},",
          " poundage_pool = #{poundagePool,jdbcType=DECIMAL},",
          " market_msk = #{marketMsk,jdbcType=DECIMAL},",
          " company_msk = #{companyMsk,jdbcType=DECIMAL},",
          " create_time = #{createTime,jdbcType=TIMESTAMP},",
          " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Platform record);

    @Update({
            "update t_platform",
            " set ",
            " company_msk =company_msk+#{newNumber,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void companyMskAdd(@Param("newNumber") BigDecimal newNumber, @Param("id") long id);

    @Update({
            "update t_platform",
            " set ",
            " market_fund_pool =market_fund_pool-#{newNumber,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void marketFundPoolSubtract(@Param("newNumber") BigDecimal newNumber, @Param("id") long id);

    @Update({
            "update t_platform",
            " set ",
            " company_profit_pool =company_profit_pool+#{newNumber,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void companyProfitFundsAdd(@Param("newNumber") BigDecimal newNumber, @Param("id") long id);

    @Update({
            "update t_platform",
            " set ",
            " company_profit_pool =company_profit_pool-#{newNumber,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void companyProfitFundsSubtract(@Param("newNumber") BigDecimal newNumber, @Param("id") long id);

    @Update({
            "update t_platform",
            " set ",
            " market_msk =market_msk-#{newNumber,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void marketMskSubtract(@Param("newNumber") BigDecimal newNumber, @Param("id") long id);

    @Update({
            "update t_platform",
            " set ",
            " market_msk =market_msk*#{n,jdbcType=INTEGER}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void atomicFission(@Param("n")int n, @Param("id")long id);

    @Update({
            "update t_platform",
            " set ",
            " company_msk =company_msk-#{newNumber,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void companyMskSubtract(@Param("newNumber") BigDecimal newNumber, @Param("id") long id);


    @Update({
            "update t_platform",
            " set ",
            " market_msk =market_msk+#{newNumber,jdbcType=INTEGER}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void marketMskAdd(@Param("newNumber") int newNumber, @Param("id") long id);


    @Update({
            "update t_platform",
            " set ",
            " market_fund_pool =market_fund_pool+#{newNumber,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void marketFundPoolAdd(@Param("newNumber") BigDecimal newNumber, @Param("id") long id);


    @Update({
            "update t_platform",
            " set ",
            " company_fund_pool =company_fund_pool-#{newNumber,jdbcType=DECIMAL},",
            " market_fund_pool =market_fund_pool+#{newNumber,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void companyFundToMarket(@Param("newNumber") BigDecimal newNumber, @Param("id") long id);


    @Update({
            "update t_platform",
            " set ",
            " company_fund_pool =company_fund_pool+#{newNumber,jdbcType=DECIMAL},",
            " market_fund_pool =market_fund_pool-#{newNumber,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void marketFundToCompany(@Param("newNumber") BigDecimal newNumber, @Param("id") long id);

    @Update({
            "update t_platform",
            " set ",
            " bonus_pool =bonus_pool-#{newNumber,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void bonusPoolSubstract(@Param("newNumber") BigDecimal newNumber, @Param("id") long id);

    @Update({
            "update t_platform",
            " set ",
            " bonus_pool =bonus_pool+#{newBonus,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void bonusPoolAdd(@Param("newBonus") BigDecimal newNumber, @Param("id") long id);

    @Update({
            "update t_platform",
            " set ",
            " poundage_pool =poundage_pool+#{newNumber,jdbcType=DECIMAL}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    void poundagePoolAdd(@Param("newNumber") BigDecimal newNumber, @Param("id") long id);
}